package ru.st.selenium.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;


public class FilmAddPage extends InternalPage {

	public FilmAddPage(PageManager pages) {
		super(pages);
	}
	
	@FindBy(name = "name")
	private WebElement TitleField;
	
  @FindBy(name = "year")
  private WebElement yearField;
  
  @FindBy(name = "duration")
  private WebElement durationField;
  
  @FindBy(name = "languages")
  private WebElement languagesField;
  
  @FindBy(name = "country")
  private WebElement countryField;
  
  @FindBy(id = "submit")
  private WebElement saveButton;

  public String getTitle() {
    return TitleField.getAttribute("value");
  }

  public FilmAddPage setTitleField(String text) {
    TitleField.sendKeys(text);
    return this;
  }

  public String getYear() {
    return yearField.getAttribute("value");
  }

  public FilmAddPage setYearField(String text) {
    yearField.sendKeys(text);
    return this;
  }

  public FilmAddPage setDuration(String text) {
    durationField.sendKeys(text);
    return this;
  }

  public String getDuration() {
	    return durationField.getAttribute("value");
	  }


  public String getLanguages() {
	  return languagesField.getAttribute("value");
  }

  public FilmAddPage setLanguages(String text) {
	languagesField.sendKeys(text);
    return this;
  }

  public String getCountry() {
	  return countryField.getAttribute("value");
  }

  public FilmAddPage setCountry(String text) {
	countryField.sendKeys(text);
    return this;
  }
  
  public void clickSaveButton() {
		saveButton.click();
	}
  public FilmAddPage ensurePageLoaded() {
    super.ensurePageLoaded();
    wait.until(presenceOfElementLocated(By.className("addmovie")));
    return this;
  }


}
